package v1

import (
	"card/app/http/controllers/api"
	"card/app/requests"
	"card/pkg/file"
	"card/pkg/response"
	"github.com/gin-gonic/gin"
)

type UploadController struct {
	api.BaseApiController
}

func (ctrl *UploadController) Upload(ctx *gin.Context) {
	request := &requests.UploadImageRequest{}
	if err := requests.Validate(ctx, request, requests.UploadImage); err != nil {
		response.Error(ctx, err)
		return
	}
	avatar, err := file.SaveUploadAvatar(ctx, request.Image)
	if err != nil {
		response.Error(ctx, err, "头像上传失败")
		return
	}
	response.Data(ctx, avatar)
}
